﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using BusinessLogic.ClassFactory;
using ValidateCommon;

namespace RichECMS.ServerPages.Links
{
    public partial class LinkGroupUpdate : Util.BasePage.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["Gid"] != null)
                {
                    if (!ParamAuth.IsNumber(Request["Gid"].ToString().Trim()))
                    {
                        Alert("参数错误");
                        return;
                    }
                    else
                    {
                        State.intLinkGroupID = int.Parse(Request["Gid"].ToString());
                        InitDataBind(State.intLinkGroupID);
                    }
                }
            }
        }

        /// <summary>
        /// 页面输出
        /// </summary>
        private void InitDataBind(int intLinGroupId)
        {
            //栏目状态
            using (LinksGroupFactory objSectionFactory = new LinksGroupFactory())
            {
                BusinessLogic.BusinessRules.LinksGroup objSections = objSectionFactory.Creator(intLinGroupId);
                if (objSections != null)
                {
                    this.txtTitleCN.Value = objSections.DataItem.chvGName;
                }
            }
        }

        /// <summary>
        /// 验证输入
        /// </summary>
        private bool ValidateValues()
        {
            bool bolIsValidate = true;
            if (this.txtTitleCN.Value.Trim().Length == 0)
            {
                Alert("请填写栏目中文名称");
                bolIsValidate = false;
            }
            return bolIsValidate;
        }

        /// <summary>
        /// 提交数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitBtnHander(object sender, ImageClickEventArgs e)
        {
            if (!ValidateValues())
            {
                return;
            }
            using (LinksGroupFactory objFactory = new LinksGroupFactory())
            {
                BusinessLogic.BusinessRules.LinksGroup objLinksGroup = objFactory.Creator(State.intLinkGroupID);
                objLinksGroup.DataItem.chvGName = this.txtTitleCN.Value;
                objLinksGroup.DataItem.intIssueState = 0;
                objLinksGroup.Update();
            }
            AlertAndRedirectAndExecOther("修改链接组成功！", "LinkGroupUpdate.aspx?Gid=" + State.intLinkGroupID, false, "window.parent.refrashleft();");
        }

        protected void DeleteThisLinkGroup(object sender, EventArgs e)
        {
            try
            {
                using (LinksGroupFactory objFactory = new LinksGroupFactory())
                {
                    BusinessLogic.BusinessRules.LinksGroup objLinksGroup = objFactory.Creator(Convert.ToInt32(Request["Gid"]));
                    objLinksGroup.Delete(Convert.ToInt32(Request["Gid"]));
                }
                AlertAndRedirectAndExecOther("删除链接组成功！即将跳转，请稍候", "SectionsManage.aspx", false, "window.parent.refrashleft();");
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
            }
        }

        protected void ImageButtonReset_Click(object sender, ImageClickEventArgs e)
        {

        }
    }
}